package com.haopt.annotation.importlearn;

import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @author haopt
 * @version 1.0
 * @ClassName MyImportBeanDefinitionRegistrar
 * @Description 动态创建bean对象
 * @date 2021/5/12 14:51
 */
public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry beanDefinitionRegistry) {
        AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(Import.class).getBeanDefinition();
        beanDefinitionRegistry.registerBeanDefinition("import",beanDefinition);
    }
}
